export function isCardID(rule, sId, callback) {
    console.log(sId)
    if (!sId) {
        callback(new Error('身份证号不能为空'));
        return
    }
    var iSum = 0;
    var sBirthday = sId.substr(6, 4) + "-" + Number(sId.substr(10, 2)) + "-" + Number(sId.substr(12, 2));
    var d = new Date(sBirthday.replace(/-/g, "/"));
    for (var i = 17; i >= 0; i--) {
        iSum += (Math.pow(2, i) % 11) * parseInt(sId.charAt(17 - i), 11);
    }
  
        if (!/^\d{17}(\d|x|X)$/i.test(sId)) {
            callback(new Error('你输入的身份证长度或格式错误'));
        }

        else if (sBirthday != (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate())) {
            callback(new Error('身份证上的出生日期非法'));
        }

     else {
            callback();
        }

}
// 手机号验证
export function phone(rule, value, callback) {
    var regex = /^1\d{10}$/
    if (!regex.test(value)) {
        callback(new Error('请输入正确的手机号'));
    } else {
        callback();
    }
}
export function email(rule, value, callback) {
    var regex = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
    if (!regex.test(value)) {
        callback(new Error('请输入正确的邮箱'));
    } else {
        callback();
    }
}
export function username(val) {
    var regex = /^(([\u4e00-\u9fa5]{2,5})|([a-zA-Z]+\s?[a-zA-Z]+))$/
    if (!regex.test(val)) {
        return '请输入2-5位姓名'
    } else {
        return true
    }
}

export function brankCard(rule, value, callback) {
    var regex =/^([1-9]{1})(\d{15}|\d{18})$/; 
    if (!regex.test(value)) {
        callback(new Error('请输入正确的银行卡号'));
    } else {
        callback();
    }
}